package yhp.com.zijie.web;

import yhp.com.zijie.bean.Users;
import yhp.com.zijie.service.UsersService;
import yhp.com.zijie.service.impl.UsersServiceImpl;
import yhp.com.zijie.util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/power/user/users")
public class UserServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        if ("select".equals(method)){
            select(req,resp);
        }




    }

    protected void select(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //当前页
        String index = req.getParameter("index");
        int pageIndex = (index==null||index.length()==0)?1:Integer.parseInt(index);

        //调用方法(查询用户列表， 查询总条数)
        UsersService usersService = new UsersServiceImpl();
        PageUtil pageUtil = new PageUtil();
        //查询用户列表
        List<Users> usersList = usersService.getUsersList(pageIndex, pageUtil.getPageSize());

        //查询总条数
        int total = usersService.total();

        //赋值给pageUtil工具类
        pageUtil.setPageIndex(pageIndex);
        pageUtil.setTotal(total);
        pageUtil.setDataList(usersList);

        //存储值，传给前端
        req.setAttribute("pi" , pageUtil);

        //跳转页面
        req.getRequestDispatcher("list.jsp").forward(req , resp);

    }
}








































